<template>
  <header>
    <div class="l-content">
      <!-- 左侧折叠图标 -->
      <div class="icon" @click="Collapse">
        <i :class="isCollapse ?'el-icon-s-unfold':'el-icon-s-fold'"></i>
      </div>

      <!-- <el-button icon="el-icon-s-fold" size="mini" @click="Collapse"></el-button> -->
      <!-- 面包屑 -->
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item v-for="item in getTab" :key="item.name" :to="{ path: item.path }" :class="[$route.name === item.name ? 'activeTab' : '']">{{ item.label }}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <!-- 右侧头像 -->
    <div class="r-content">
      <!-- 消息 -->
      <el-popover placement="bottom" :width="400" trigger="hover">
        <div class="notice-lists">
          <div class="title">通知</div>
          <div class="item " v-for="item in noteList" :key="item.id">
            <span class="type">通知</span>
            {{ item.text }}
          </div>
        </div>

        <div class="bell" slot="reference">
          <i class="el-icon-bell"></i>
        </div>

      </el-popover>

      <el-dropdown trigger="hover" size="small" placement="bottom">
        <div class="flx-center">
          <div class="avatar">
            <img :src="require(`@/assets/images/${getUserInfo.avatar}`)" />
          </div>
          <span class="username">{{ getUserInfo.role }}</span>
        </div>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item>个人中心</el-dropdown-item>
            <el-dropdown-item @click.native="gotoLogin">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>

      </el-dropdown>
    </div>
  </header>
</template>

<script>
export default {
  name: 'Header',
  data() {
    return {
      isTure: 'activeTab',
      visible: false,
      noteList: []
    }
  },
  methods: {
    Collapse() {
      this.$store.commit('setIsCollapse')
    },
    // 登录退出
    gotoLogin() {
      //清除token
      sessionStorage.removeItem('token')
      //清除菜单
      this.$store.commit('clearMenu')
      //跳转到登录页面
      this.$router.push({ name: 'login' })
    }
  },
  computed: {
    //伸缩菜单栏
    isCollapse() {
      return this.$store.state.users.isCollapse
    },
    getUserInfo() {
      return JSON.parse(sessionStorage.getItem('setUserInfo')) || this.$store.state.users.UserInfo
    },
    // 获取面包屑数据
    getTab() {
      return this.$store.state.tabs.tabsList
    }
  },
  async created() {
    const { data: res } = await this.$http.get('/note/getnote')
    if (res.code === 200) this.noteList = res.data
    console.log(res.data)
  }
}
</script>

<style lang="less">
.el-breadcrumb__item {
  .el-breadcrumb__inner {
    font-weight: normal;
    color: #fdf6ec;
    &.is-link {
      font-weight: 700;
      color: #fff;
    }
  }
  .el-breadcrumb__inner:hover {
    color: #409eff;
  }
  .el-breadcrumb__separator {
    color: #fdf6ec;
  }

  &:last-child {
    .el-breadcrumb__inner {
      color: #fff;
    }
    .el-breadcrumb__inner:hover {
      font-weight: 700;
      color: #409eff;
    }
  }
}

/* 面包屑 */
</style>

<style lang="less" scoped>
header {
  display: flex;
  height: 100%;
  justify-content: space-between;
  align-items: center;

  .l-content {
    .icon {
      margin-right: 16px;
      font-size: 24px;
      color: #fff;
    }
    display: flex;
    align-items: center;
    .el-button {
      margin-right: 20px;
    }
  }
  .r-content {
    position: relative;
    .bell {
      position: absolute;
      top: 12px;
      left: -45px;
      .el-icon-bell {
        font-size: 20px;
        color: #fff;
      }
    }

    .flx-center {
      display: flex;
      align-items: center;
      margin-right: 20px;
      .avatar {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        overflow: hidden;
        // margin-right: 10px;
      }
      .username {
        font-size: 18px;
        color: #fff;
        // margin-right:50px
        margin: 0 0 0 10px;
      }
      img {
        width: 100%;
        height: 100%;
      }
    }
  }
}
.notice-lists {
  height: 260px;
  overflow: scroll;
  .title {
    padding-bottom: 6px;
    border-bottom: 2px solid #dcdfe6;
    font-size: 18px;
    margin: 3px 20px 10px 7px;
    color: #4060c7;
  }
  .item {
    font-size: 14px;
    padding: 10px;
    color: #666;

    .type {
      font-size: 10px;
      padding: 5px 10px;
      font-weight: 500;
      line-height: 0px;
      color: #fa4a1e;
      text-align: left;
      border-radius: 6px;
      background: #fa4a1e14;

      &.error-type {
        color: #4060c7;
        background: #e8f3ff;
      }
    }
  }
}
/deep/.activeTab {
  font-size: 16px;
}
</style>
